//
//  MYHttpClient.m
//  JQLive
//
//  Created by Bruce on 2019/11/28.
//  Copyright © 2019 mlqk. All rights reserved.
//

#import "MYHttpClient.h"

@implementation MYHttpClient
// 通用配置
+ (MYHttpClient *)sharedPublicManager{
    static MYHttpClient *publicBaseManager = nil;
        
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        //如果设置了 服务器主地址 , 那么后面请求就不用拼接了 .
        //当然我试了下这里加主地址 , 请求时又拼接了主地址 , 也访问成功了.
//        publicBaseManager = [[MYHttpClient alloc]init];
        publicBaseManager = [[MYHttpClient alloc]initWithBaseURL:[NSURL URLWithString:PublicBaseUrl_user]];
//        httpManager = [ZSPHTTPClient manager];
//        超时断开
        publicBaseManager.requestSerializer.timeoutInterval = 30;

        
        publicBaseManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", @"text/json", @"text/javascript",@"text/plain",@"image/gif",@"application/x-www-form-urlencoded",@"charset=UTF-8",  nil];
        [publicBaseManager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8;application/json;text/html;text/json;text/javascript;text/plain;image/gif;application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

        //现在貌似不用写接收类型了，试了试访问@"https://baidu.com",提示不能接收@"text/html"类型 , 我写下述一句 , 和写上面接收类型一样的效果
        publicBaseManager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        //设置访问请求头 , 请求头是服务器限制用来限制访问而要求客户端添加的一个标识 . 就好比是一个暗号 . 如果服务端没做要求 , 不用加请求头也可以
//        [httpManager.requestSerializer setValue:@"doAction" forHTTPHeaderField:@"te_method"];
//        [httpManager.requestSerializer setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
//        [httpManager.requestSerializer setValue:@"2.2" forHTTPHeaderField:@"te_version"];
//        [httpManager.requestSerializer setValue:@"moa" forHTTPHeaderField:@"party_id"];
    });
    
    //设置安全策略 (https) ,数字证书验证,此段具体实现 , 后期更新 ...
//    httpManager.securityPolicy = [httpManager customSecurityPolicy];
    
    return publicBaseManager;
}
//设置单例
+ (MYHttpClient *)sharedNoBaseUrlManager{
    static MYHttpClient *noBaseUrlhttpManager = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        //如果设置了 服务器主地址 , 那么后面请求就不用拼接了 .
        //当然我试了下这里加主地址 , 请求时又拼接了主地址 , 也访问成功了.
        noBaseUrlhttpManager = [[MYHttpClient alloc]init];
        
//        httpManager = [ZSPHTTPClient manager];
//        超时断开
        noBaseUrlhttpManager.requestSerializer.timeoutInterval = 30;

        
        noBaseUrlhttpManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", @"text/json", @"text/javascript",@"text/plain",@"image/gif",@"application/x-www-form-urlencoded",@"charset=UTF-8",  nil];
        [noBaseUrlhttpManager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=UTF-8;application/json;text/html;text/json;text/javascript;text/plain;image/gif;application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

        //现在貌似不用写接收类型了，试了试访问@"https://baidu.com",提示不能接收@"text/html"类型 , 我写下述一句 , 和写上面接收类型一样的效果
        noBaseUrlhttpManager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        //设置访问请求头 , 请求头是服务器限制用来限制访问而要求客户端添加的一个标识 . 就好比是一个暗号 . 如果服务端没做要求 , 不用加请求头也可以
//        [httpManager.requestSerializer setValue:@"doAction" forHTTPHeaderField:@"te_method"];
//        [httpManager.requestSerializer setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
//        [httpManager.requestSerializer setValue:@"2.2" forHTTPHeaderField:@"te_version"];
//        [httpManager.requestSerializer setValue:@"moa" forHTTPHeaderField:@"party_id"];
    });
    
    //设置安全策略 (https) ,数字证书验证,此段具体实现 , 后期更新 ...
//    httpManager.securityPolicy = [httpManager customSecurityPolicy];
    
    return noBaseUrlhttpManager;
}

@end
